# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: helpers\hashing\__init__.py
__author__ = "Attila Gerendi (Sanyi)"
import hashlib, hmac, random


def random_hex_digits(length=10):
    return ("").join([random.choice("0123456789abcdef") for _ in range(0, length)])


def sha512(value, salt=None):
    m = hashlib.sha512()
    if salt:
        m.update(salt.encode("utf-8"))
    m.update(value.encode("utf-8"))
    return m.hexdigest()


def sha256(value, salt=None):
    m = hashlib.sha256()
    if salt:
        m.update(salt.encode("utf-8"))
    m.update(value.encode("utf-8"))
    return m.hexdigest()


def md5b(value, salt=None):
    m = hashlib.md5()
    if salt:
        m.update(salt)
    m.update(value)
    return m.hexdigest().encode("utf-8")


def md5(value, salt=None):
    m = hashlib.md5()
    if salt:
        m.update(salt.encode("utf-8"))
    m.update(value.encode("utf8"))
    return m.hexdigest()


def hmac256hex(data, secret):
    m = hmac.new(secret.encode("utf-8"), digestmod=hashlib.sha256)
    m.update(data.encode("utf-8"))
    return m.hexdigest()
